package com.ithinks.flow.common.utils.protocol.socket.nio;

import java.io.IOException;
import java.util.Scanner;

/**
 * @Description
 * @ClassName NioClient
 * @Author MR.LI
 * @date 2020.12.08 17:57
 */
public class NioClient {

    private static NioClientHandler nioClientHandler;

    public static void start(){
        if(nioClientHandler !=null)
            nioClientHandler.stop();
        nioClientHandler = new NioClientHandler("127.0.0.1",8888);
        new Thread(nioClientHandler,"Client").start();
    }

    public static boolean sendMsg(String msg) throws IOException {
        nioClientHandler.sendMsg(msg);
        return true;
    }

    public static void main(String[] args) throws IOException {
        start();
        Scanner scanner = new Scanner(System.in);
        while(NioClient.sendMsg(scanner.next()));
    }

}
